/**
 * 头部拦截器 处理请求头的配置
 */
import {getStorageSync} from "@tarojs/taro";

export default function (chain) {
  const requestParams = chain.requestParams

  const { header } = requestParams

  // 获取 token
  const token = getStorageSync('token')

  // 如果有 token，添加到 header
  if (token) {
    console.log(`用户token ${token}`)
    requestParams.header = {
      ...header,
      'Authorization': `Bearer ${token}`
    }
  } else {
    requestParams.header = header
  }

  return chain.proceed(requestParams)
}
